package com.ycc.biz.common;

import com.baomidou.mybatisplus.core.handlers.MetaObjectHandler;
import org.apache.ibatis.reflection.MetaObject;
import org.springframework.stereotype.Component;

import java.time.LocalDateTime;

@Component
public class MetaObjectHandlerImpl implements MetaObjectHandler {
    @Override  
    public void insertFill(MetaObject metaObject) {
        // 填充创建时间  
        this.strictInsertFill(metaObject, "createTime", LocalDateTime::now, LocalDateTime.class);
        // 填充创建人（从上下文获取，如JWT）  
        this.strictInsertFill(metaObject, "createdBy", () -> getCurrentUser(), String.class);  
    }  

    @Override  
    public void updateFill(MetaObject metaObject) {  
        // 填充更新时间  
        this.strictUpdateFill(metaObject, "updateTime", LocalDateTime::now, LocalDateTime.class);  
        // 填充更新人  
        this.strictUpdateFill(metaObject, "updatedBy", () -> getCurrentUser(), String.class);  
    }  

    private String getCurrentUser() {  
        // 实现获取当前用户逻辑（如Spring Security上下文）
        // TODO: 实现获取当前用户逻辑
        return "admin"; // 示例值  
    }  
}  
